package com.jsy.common.wps;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
@Data
public class Result<T> {
    private boolean success = true;
    private String errorCode = "0";
    private String errorMsg = null;
    private List<T> data = new ArrayList<>();

    public Result() {}
    public Result(List<T> data) {
        if (data != null && data.size() > 0) {
            this.data = data;
        }
    }
    public Result(T data) {
        this.data.add(data);
    }

    // 成功时
    public static Result ok() {
        return new Result();
    }

    public static Result ok(List data) {
        Result r = new Result();
        r.setData(data);
        return r;
    }

    // 异常时
    public static Result error(String code, String msg) {
        Result r = new Result();
        r.setSuccess(false);
        r.setErrorCode(code);
        r.setErrorMsg(msg);
        return r;
    }

    private void setSuccess(boolean b) {
        this.success = b;
    }
	// 省略getter、setter和tostring
}
